<script>
import { mapState, mapMutations, mapActions } from 'vuex';
import Vue from 'vue';
export default {
	onLaunch: function() {
		console.log('App Launch');
		let that = this;
		uni.getSystemInfo({
			success: function(e) {
				// #ifndef MP
				Vue.prototype.StatusBar = e.statusBarHeight;
				if (e.platform == 'android') {
					Vue.prototype.CustomBar = e.statusBarHeight + 50;
				} else {
					Vue.prototype.CustomBar = e.statusBarHeight + 45;
				}
				// #endif

				// #ifdef MP-WEIXIN
				Vue.prototype.StatusBar = e.statusBarHeight;
				let custom = wx.getMenuButtonBoundingClientRect();
				console.log(custom);
				console.log(e.statusBarHeight);
				Vue.prototype.Custom = custom;
				Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
				// #endif

				// #ifdef MP-ALIPAY
				Vue.prototype.StatusBar = e.statusBarHeight;
				Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
				// #endif
				/* 计算一下 宽高比例 */
				// e.windowHeight / 750;
				// that.SET_CustomBar(Vue.prototype.CustomBar);
				// that.SET_StatusBar(Vue.prototype.StatusBar);
			}
		});
		this.getCode();
	},
	onShow: function() {
		console.log('App Show');
	},
	onHide: function() {
		console.log('App Hide');
	},
	methods: {
		...mapMutations(['login']),
		getCode() {
			let $me = this;
			uni.login({
				provider: 'weixin',
				success: function(loginRes) {
					let code = loginRes.code;
					$me.getSession(code);
				}
			});
		},

		getSession(code) {
			this.$getajax(this.$api.getSession, { code }).then(da => {
				if (da.code == 200) {
					this.login(da.data);
				}
			});
		}
	}
};
</script>

<style>
@import 'colorui/main.css';
@import 'colorui/icon.css';
.submitBtn,
.cancelBtn,
.defaultBtn {
	color: #fff;
	text-align: center;
	background: #db6553;
	line-height: 79upx;
	font-size: 39upx;
	display: block;
}
.submitBtn {
	background: #39b54a;
	color: #ffffff;
}
.cancelBtn {
	background: #f0f0f0;
	color: #db6553;
}

.defaultBtn {
	background: #de715d;
}
.defultColor {
	color: #de715d !important;
}
.orange {
	color: orange !important;
}
/*每个页面公共css */
</style>
